package com.bit.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
//@Component
public class AspectDemo {

    @Pointcut("execution (* com.bit.aop.controller.*.*(..)))")
    private void pt(){}

//    @Before("execution (* com.bit.aop.controller.*.*(..)))")
    @Before("pt()")
    public void doBefore() {
      log.info("AspectDemo -> doBefore..");
    }

//    @After("execution (* com.bit.aop.controller.*.*(..)))")
    @After("pt()")
    public void doAfter(){
        log.info("AspectDemo -> doAfter..");
    }
//    @AfterReturning("execution (* com.bit.aop.controller.*.*(..)))")
    @AfterReturning("pt()")
    public void doAfterreturing() {
        log.info("AspectDemo -> doAfterreturing..");
    }

//    @AfterThrowing("execution (* com.bit.aop.controller.*.*(..)))")
    @AfterThrowing("pt()")
    public void doAfterThrowing() {
        log.info("AspectDemo -> doAfterThrowing..");
    }

//    @Around("execution (* com.bit.aop.controller.*.*(..)))")
    @Around("pt()")
    public Object doAround(ProceedingJoinPoint joinPoint) {
        log.info("AspectDemo -> doAround before..");
        Object proceed = null;
        try {
            proceed = joinPoint.proceed();
            log.info("AspectDemo -> doAround after..");

        }catch (Throwable throwable){
            log.error("发生异常, throwable: ", throwable);
        }
        return proceed;
    }
}
